package main

import (
	"fmt"
	"strings"
)

//0ms 100%, 1.8MB 87%
func replaceSpace(s string) string {
	return strings.Replace(s, " ", "%20", -1)
}

//0ms 100%, 1.8MB 87%
func replaceSpace1(s string) string {
	space := 0
	for _, v := range s {
		if v == ' ' {
			space++
		}
	}
	res := make([]byte, len(s)+2*space)
	j := len(res) - 1
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] != ' ' {
			res[j] = s[i]
			j--
		} else {
			res[j] = '0'
			res[j-1] = '2'
			res[j-2] = '%'
			j -= 3
		}
	}
	return string(res)
}

func main() {
	fmt.Println(replaceSpace("ds dsds "))
	fmt.Println(replaceSpace1("ds dsds "))
}
